<?php

namespace app\admin\model\user;

use app\common\model\TimeModel;

class User extends TimeModel
{

    protected $name = "user";

    protected $deleteTime = "delete_time";

    //返回用户的信息
    protected static $selectField = 'id,username,password,nickname,avatar,money,integral,level';

    /**
     * Author:Zhongyuan Lu
     * 成为会员时间
     * @param $value
     * @return false|int|string
     */
    public function getMemberTimeAttr($value)
    {
        return $value ? date('Y-m-d',$value) : 0;
    }

    /**
     * Author:Zhongyuan Lu
     * 会员过期时间
     * @param $value
     * @return false|int|string
     */
    public function getOverdueTimeAttr($value)
    {
        return $value ? date('Y-m-d',$value) : 0;
    }

    /**
     * 根据条件查询单条记录
     * @param $where
     * @return array|Model|null
     */
    public static function whereFind($where)
    {
        return self::where($where)->field(self::$selectField)->find();
    }

    /**
     * 根据id查询单条记录
     * @param $id
     * @return array|Model|null
     */
    public static function idFind($id)
    {
        return self::field(self::$selectField)->find($id);
    }

    /**
     * 创建一天记录
     * @param $params
     * @return mixed
     */
    public static function createOne($params)
    {
        return self::create($params)->id;
    }

    /**
     * 根据id修改单条记录
     * @param $id
     * @param $data
     * @return User
     */
    public static function updateOne($id,$data)
    {
        return self::where('id',$id)->update($data);
    }


    public function userBank()
    {
        return $this->hasMany(UserBank::class,'uid','id');
    }
}